package com.excellence.service.impl;

import com.excellence.mapper.OperationMapper;
import com.excellence.pojo.Operation;
import com.excellence.service.OperationService;
import com.excellence.utils.SaveFilesPath;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.List;

/**
 * @author 沈秉璋
 * @ClassName OperationServiceImpl
 * @Description TODO
 * @date 2024/4/8 10:50
 * @Version 1.0
 */
@Service
public class OperationServiceImpl implements OperationService {
    @Autowired
    OperationMapper operationMapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return operationMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Operation record) {
        return operationMapper.insert(record);
    }

    @Override
    public int insertSelective(Operation record, List<MultipartFile> files) {
        if (files != null) {
            record.setOperationImage(SaveFilesPath.saveFilesPath(files));
        }
        record.setOperationTime(new Date());
        return operationMapper.insertSelective(record);
    }

    @Override
    public List<Operation> selectByUserId(Long id) {
        return operationMapper.selectByUserId(id);
    }

    @Override
    public List<Operation> selectAll() {
        return operationMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKeySelective(Operation record, List<MultipartFile> files) {
        if (files != null) {
            record.setOperationImage(SaveFilesPath.saveFilesPath(files));
        }
        record.setOperationTime(new Date());
        return operationMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Operation record, List<MultipartFile> files) {
        if (files != null) {
            record.setOperationImage(SaveFilesPath.saveFilesPath(files));
        }
        record.setOperationTime(new Date());
        return operationMapper.updateByPrimaryKey(record);
    }

    @Override
    public int count(Integer massifId) {
        return operationMapper.count(massifId);
    }
}
